package com.hnu.highlynewapp.service.impl;

import com.hnu.highlynewapp.entity.ContactEntity;
import com.hnu.highlynewapp.entity.UserEntity;
import com.hnu.highlynewapp.service.ContactService;
import com.hnu.highlynewapp.service.UserService;
import com.hnu.highlynewapp.vo.PublishActivityVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hnu.highlynewapp.utils.PageUtils;
import com.hnu.highlynewapp.utils.Query;

import com.hnu.highlynewapp.dao.ActivityDao;
import com.hnu.highlynewapp.entity.ActivityEntity;
import com.hnu.highlynewapp.service.ActivityService;


@Service("activityService")
public class ActivityServiceImpl extends ServiceImpl<ActivityDao, ActivityEntity> implements ActivityService {

    @Autowired
    private ContactService contactService;

    @Autowired
    private UserService userService;

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<ActivityEntity> page = this.page(
                new Query<ActivityEntity>().getPage(params),
                new QueryWrapper<ActivityEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public void publish(PublishActivityVo vo) {
        ContactEntity contactEntity = new ContactEntity();
        BeanUtils.copyProperties(vo,contactEntity);
        contactEntity.setName(vo.getContactName());
        contactEntity.setAddress(vo.getContactAddress());
        Long contactId = contactService.saveAndCheckExist(contactEntity);

        ActivityEntity activityEntity = new ActivityEntity();
        BeanUtils.copyProperties(vo,activityEntity);
        activityEntity.setPublishTime(new Date());
        activityEntity.setName(vo.getActivityName());
        activityEntity.setAddress(vo.getActivityAddress());
        activityEntity.setContactId(contactId);
        baseMapper.insert(activityEntity);
    }


}